﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using DataBaseLib.Entities;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPFSqlSugarDemo.Model;

namespace WPFSqlSugarDemo.ViewModel
{
   
    public class MainViewModel:ObservableObject
    {
        #region 属性
        private ObservableCollection<Student> studentList;
        public ObservableCollection<Student> StudentList { get => studentList; set => SetProperty(ref studentList, value); }
        #endregion

        #region 命令
        public RelayCommand<object> DeleCommand { get; set; }
        public RelayCommand<object> EditCommand { get; set; }
        #endregion

        public MainViewModel()
        {
            DeleCommand = new RelayCommand<object>(DelOperate);
            EditCommand = new RelayCommand<object>(EditOperate);
            var list = DataCenter.studentBLL.GetAllStudentList();
            studentList = new ObservableCollection<Student>(list);
        }

        private void EditOperate(object obj)
        {
            Student student = obj as Student;
            MessageBox.Show("弹出编辑框！", "提示", MessageBoxButton.OK);
        }

        private void DelOperate(object obj)
        {
            Student student = obj as Student;
            StudentList.Remove(StudentList.FirstOrDefault(x=>x.Id== student.Id));
            //if (DataCenter.studentBLL.DelStudentById(id))
            {
                MessageBox.Show("删除成功！","提示",MessageBoxButton.OK);
            }
        }
    }
}
